package com.itita.ww2.data;

import java.util.HashMap;
import java.util.Map;

import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;

public class PlayerConfig {
	public static boolean isLoaded; // 是否已经载入过
	private static ISFSObject playerConfig; // 用户数据配置
	private static ISFSObject fatigueCfg; // 体力配置
	// 
	private static ISFSObject game_init; // 帐号初始数据
	private static ISFSObject wm_init; // 大地图初始数据

	public static void init(ISFSObject data) {
		PlayerConfig.playerConfig = data.getSFSObject("config");
		PlayerConfig.fatigueCfg = data.getSFSObject("fatigueCfg");
		PlayerConfig.game_init = data.getSFSObject("gm_init");
		PlayerConfig.wm_init = data.getSFSObject("wm_init");
		PlayerConfig.isLoaded = true;
	}

	/*
	 * Initial...
	 */
	public static final ISFSObject getGameInitResource() {
		return game_init.getSFSObject("resource");
	}

	public static final int getGameInitFatigue() {
		return game_init.getSFSObject("info").getInt("fatigue");
	}

	public static final int getGameInitLevel() {
		return game_init.getSFSObject("info").getInt("lv");
	}

	public static final int getGameInitExp() {
		return game_init.getSFSObject("info").getInt("exp");
	}

	public static final ISFSObject getGameInitArmy() {
		return game_init.getSFSObject("army");
	}

	public static final ISFSObject getGameInitScience() {
		return game_init.getSFSObject("science");
	}

	public static final ISFSArray getGameInitInventory() {
		return game_init.getSFSArray("inventory");
	}

	public static final ISFSObject getGameInitBuilding() {
		return game_init.getSFSObject("buildings");
	}

	/////////////////////////////////////////

	public static final ISFSObject getWMInitUnlockData() {
		return wm_init.getSFSObject("unlockData");
	}

	public static final int getWMInitBaseOccTimes() {
		return wm_init.getInt("base_occTimes");
	}

	public static final int getWMInitBaseDefTimes() {
		return wm_init.getInt("base_occTimes");
	}

	public static final int getWMInitBaseCount() {
		return wm_init.getInt("base_count");
	}
	/*
	 * Player...
	 */

	/**
	 * 获取资源更新时间间隔
	 */
	public static final int getResHarvestDuration() {
		return playerConfig.getInt("HarvestTime");
	}

	/**
	 * 获取疲劳回复时间间隔
	 */
	public static final int getFatigueDuration() {
		return playerConfig.getInt("fatigueRestoreTime");
	}

	/**
	 * 获取疲劳最大值
	 */
	public static final int getMaxFatiguePoints(int level) {
		return playerConfig.getSFSObject("FatigueLimit").getInt(String.valueOf(level));
	}

	/**
	 * 获取不同次数的金条比例
	 */
	public static final int getGoldPerFatigue(int times) {
		return fatigueCfg.getSFSArray("GoldRatio").getInt(times);
	}

	/**
	 * 获取vip等级对应最大购买次数
	 */
	public static final int getFatigueBuyLimit(int vipLv) {
		return fatigueCfg.getSFSArray("VipTimes").getInt(vipLv);
	}

	/**
	 * 获取疲劳购买次数重置时间点
	 */
	public static final String getFatigueResetTimeLine() {
		return fatigueCfg.getSFSObject("ResetTime").getUtfString("time");
	}

	/**
	 * 获取疲劳购买次数重置时间对应时区
	 */
	public static final String getFatigueResetTimeZone() {
		return fatigueCfg.getSFSObject("ResetTime").getUtfString("zone");
	}

	/**
	 * 获取level等级升级需要的经验<br>
	 * level -> level + 1
	 */
	public static final int getNeedExp(int level) {
		return playerConfig.getSFSObject("Experience").getInt(String.valueOf(level));
	}

	/**
	 * 玩家最大等级
	 */
	public static final int getMaxLevel() {
		return playerConfig.getSFSObject("Experience").size() + 1;
	}

	/**
	 * 派兵量
	 */
	public static final int getDispatchCount(int level) {
		return playerConfig.getSFSObject("DispatchLimit").getInt(String.valueOf(level));
	}

	/**
	 * 兵库存量
	 */
	public static final int getArmyStockCount(int level) {
		return playerConfig.getSFSObject("ArmyStockLimit").getInt(String.valueOf(level));
	}

	/**
	 * 资源库存(最大限制)
	 */
	public static final long getMaxResource(String resCode, int level) {
		return playerConfig.getSFSObject("ResStockLimit").getSFSObject(resCode).getLong(String.valueOf(level));
	}

	/**
	 * 资源库存表
	 */
	public static final Map<String, Long> getMaxResourceMap(int level) {
		Map<String, Long> ret = new HashMap<>();
		ISFSObject rsl = playerConfig.getSFSObject("ResStockLimit");
		for (String key : rsl.getKeys()) {
			ret.put(key, rsl.getSFSObject(key).getLong(String.valueOf(level)));
		}
		ret.put("R004", Long.MAX_VALUE);
		return ret;
	}

	public static final ISFSObject getPlayerConfig() {
		return playerConfig;
	}
}
